package com.xiaofan.controller;

import com.xiaofan.bean.BaseRespVo;
import com.xiaofan.exception.PasswordException;
import com.xiaofan.exception.UsernameException;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @version 1.0
 * @author: 晓帆
 **/
@RestController
@RequestMapping("user")
public class UserLoginController {
    /**
     *  判断类型返回对应的参数
     * @param username 用户名
     * @param password 密码
     * @param userId URL中含有的参数
     * @return Exception/Json/Null 根据不同情况返回不同的返回值
     * @throws Exception 异常
     */
    @RequestMapping("login/{userId}")
        public BaseRespVo login(String username, String password,@PathVariable("userId")String userId) throws Exception {
            if (username.length()<5||username.length()>10){
                throw  new UsernameException();
            }
            if (password.length()<6||password.length()>10){
                throw new PasswordException();
            }
            if(username.contains("yuanzhi")||password.contains("yuanzhi")||userId.contains("yuanzhi")){
                return BaseRespVo.ok("yuanzhi");
            }
             return null;
        }
}
